/**
 * 
 */
package org.vsg.stock.core.indicator.kline;

import org.vsg.stock.core.StockUnifiedFormater;
import org.vsg.stock.core.algorithm.Sortable;
import org.vsg.stock.core.indicator.coordinate.SimpleCoordinatePoint;

/**
 * @author Bill Vison
 *
 */
public class DegreesCoordinatePoint extends SimpleCoordinatePoint implements Sortable{

	private StockUnifiedFormater formaterInst = StockUnifiedFormater.getInstance();	
	
	private boolean hadCalculte;
	
	private Double degree;
	
	public double getDegrees() {

		double x = getXvalue();
		double y = getYvalue();
		
		if (x == 0) {
			return 0;
		}

		double angleDegress = Math.toDegrees( Math.atan( x/y ) );
		
		String angleDegressValue = formaterInst.getDegreesDecFormat().format(angleDegress);
		
		double tmp = Double.parseDouble( angleDegressValue );
		
		if ( x < 0 && y > 0 ) {
			tmp = 180 + tmp;
		}

		
		return tmp; 
	}

	
	
	@Override
	public double getValue() {
		// TODO Auto-generated method stub
		if ( degree == null ) {
			degree = getDegrees();
		}
		return degree;
	}



	@Override
	public String toString() {
		return "DegreesCoordinatePoint [getDegrees()=" + getValue()
				+ ", getXvalue()=" + getXvalue() + ", getYvalue()="
				+ getYvalue() + "]";
	}	
	
}
